# eric7.CodeFormatting.BlackFormattingDialog

Module implementing a dialog showing the Black code formatting progress and the results.

### Global Attributes

None

### Classes

BlackFormattingDialog | Class implementing a dialog showing the Black code formatting progress and the results.
BlackMultiprocessingReport | Class extending the black Report to work with multiprocessing.
BlackMultiprocessingResult | Class containing the reformatting result data.
BlackReport | Class extending the black Report to work with our dialog.
BlackStatistics | Class containing the reformatting statistic data.

### Functions

None

## BlackFormattingDialog

Class implementing a dialog showing the Black code formatting progress and the results.

### Derived from

QDialog, Ui_BlackFormattingDialog

### Class Attributes

DataRole
DataTypeRole
FileNameColumn
FileNameRole
StatusColumn
StatusRole

### Class Methods

None

### Methods

BlackFormattingDialog | Constructor
__filterFiles | Private method to filter the given list of files according the configuration parameters.
__finish | Private method to perform some actions after the run was performed or canceled.
__formatButtonClicked | Private slot handling the selection of the 'Format Code' button.
__formatManyFiles | Private method to format the list of files according the configuration using multiple processes in parallel.
__formatOneFile | Private method to format the list of files according the configuration.
__handleBlackFormattingResult | Private slot to handle the result of a black reformatting action.
__performAction | Private method to execute the requested formatting action.
__populateStatusFilterCombo | Private method to populate the status filter combo box with allowed selections.
__resizeColumns | Private method to resize the columns of the result list.
__resort | Private method to resort the result list.
__updateStatistics | Private method to update the statistics about the recent formatting run and make them visible.
closeEvent | Protected slot implementing a close event handler.
on_buttonBox_clicked | Private slot to handle button presses of the dialog buttons.
on_resultsList_itemDoubleClicked | Private slot handling a double click of a result item.
on_statusFilterComboBox_currentTextChanged | Private slot handling the selection of a status for items to be shown.

### Static Methods

__diffFormatFile | Static method to check, if the given files need to be reformatted, and generate a unified diff.
formattingWorkerTask | Static method acting as the parallel worker for the formatting task.

#### BlackFormattingDialog (Constructor)

BlackFormattingDialog(configuration, filesList, project=None, action=BlackFormattingAction.Format, lineRange=(), parent=None, )

Constructor

configuration (dict)
  dictionary containing the configuration parameters
filesList (list of str)
  list of absolute file paths to be processed
project (Project (optional))
  reference to the project object (defaults to None)
action (BlackFormattingAction (optional))
  action to be performed (defaults to BlackFormattingAction.Format)
lineRange (tuple of (int, int) (optional))
  tuple containing the start and end lines of the region to be treated (defaults to ())
parent (QWidget (optional))
  reference to the parent widget (defaults to None)

#### BlackFormattingDialog.__filterFiles

__filterFiles(filesList)

Private method to filter the given list of files according the configuration parameters.

filesList (list of str)
  list of files

Return:
  list of filtered files

Return Type:
  list of str

#### BlackFormattingDialog.__finish

__finish()

Private method to perform some actions after the run was performed or canceled.

#### BlackFormattingDialog.__formatButtonClicked

__formatButtonClicked()

Private slot handling the selection of the 'Format Code' button.

#### BlackFormattingDialog.__formatManyFiles

__formatManyFiles(files)

Private method to format the list of files according the configuration using multiple processes in parallel.

files (list of str)
  list of files to be processed

#### BlackFormattingDialog.__formatOneFile

__formatOneFile(file)

Private method to format the list of files according the configuration.

file (str)
  name of the file to be processed

#### BlackFormattingDialog.__handleBlackFormattingResult

__handleBlackFormattingResult(status, filename, data)

Private slot to handle the result of a black reformatting action.

status (str)
  status of the performed action (one of 'changed', 'failed', 'ignored', 'unchanged' or 'unmodified')
filename (str)
  name of the processed file
data (str)
  action data (error message or unified diff)

#### BlackFormattingDialog.__performAction

__performAction()

Private method to execute the requested formatting action.

#### BlackFormattingDialog.__populateStatusFilterCombo

__populateStatusFilterCombo()

Private method to populate the status filter combo box with allowed selections.

#### BlackFormattingDialog.__resizeColumns

__resizeColumns()

Private method to resize the columns of the result list.

#### BlackFormattingDialog.__resort

__resort()

Private method to resort the result list.

#### BlackFormattingDialog.__updateStatistics

__updateStatistics()

Private method to update the statistics about the recent formatting run and make them visible.

#### BlackFormattingDialog.closeEvent

closeEvent(evt)

Protected slot implementing a close event handler.

evt (QCloseEvent)
  reference to the close event

#### BlackFormattingDialog.on_buttonBox_clicked

on_buttonBox_clicked(button)

Private slot to handle button presses of the dialog buttons.

button (QAbstractButton)
  reference to the pressed button

#### BlackFormattingDialog.on_resultsList_itemDoubleClicked

on_resultsList_itemDoubleClicked(item, _column)

Private slot handling a double click of a result item.

item (QTreeWidgetItem)
  reference to the double clicked item
_column (int)
  column number that was double clicked (unused)

#### BlackFormattingDialog.on_statusFilterComboBox_currentTextChanged

on_statusFilterComboBox_currentTextChanged(status)

Private slot handling the selection of a status for items to be shown.

status (str)
  selected status

#### BlackFormattingDialog.__diffFormatFile (static)

__diffFormatFile(fast, mode, report, relSrc="", lineRange=())

Static method to check, if the given files need to be reformatted, and generate a unified diff.

src (pathlib.Path)
  path of file to be checked
fast (bool)
  flag indicating fast operation
mode (black.Mode)
  code formatting options
report (BlackReport)
  reference to the report object
relSrc (str (optional))
  name of the file relative to the project (defaults to "")
lineRange (tuple of (int, int) (optional))
  range of lines to be processed (defaults to ())

#### BlackFormattingDialog.formattingWorkerTask (static)

formattingWorkerTask(outputQueue, config)

Static method acting as the parallel worker for the formatting task.

inputQueue (multiprocessing.Queue)
  input queue
outputQueue (multiprocessing.Queue)
  output queue
config (dict)
  dictionary containing the configuration parameters

Up

## BlackMultiprocessingReport

Class extending the black Report to work with multiprocessing.

### Derived from

black.Report

### Class Attributes

None

### Class Methods

None

### Methods

BlackMultiprocessingReport | Constructor
done | Public method to handle the end of a reformat.
failed | Public method to handle a reformat failure.
path_ignored | Public method handling an ignored path.

### Static Methods

None

#### BlackMultiprocessingReport (Constructor)

BlackMultiprocessingReport(resultQueue)

Constructor

resultQueue (multiprocessing.Queue)
  reference to the queue to put the results into

#### BlackMultiprocessingReport.done

done(src, changed, diff="")

Public method to handle the end of a reformat.

src (pathlib.Path)
  name of the processed file
changed (black.Changed)
  change status
diff (str)
  unified diff of potential changes (defaults to "")

#### BlackMultiprocessingReport.failed

failed(src, message)

Public method to handle a reformat failure.

src (pathlib.Path)
  name of the processed file
message (str)
  error message

#### BlackMultiprocessingReport.path_ignored

path_ignored(src, message="")

Public method handling an ignored path.

src (pathlib.Path or str)
  name of the processed file
message (str (optional))
  ignore message (default to "") (unused)

Up

## BlackMultiprocessingResult

Class containing the reformatting result data.

This class is used when reformatting multiple files in parallel using processes.

### Derived from

None

### Class Attributes

data
filename
status

### Class Methods

None

### Methods

None

### Static Methods

None

Up

## BlackReport

Class extending the black Report to work with our dialog.

### Signals

result(status, file name, data)
  emitted to signal the reformatting result as three strings giving the status (one of 'changed', 'unchanged', 'unmodified', 'failed' or 'ignored'), the file name and data related to the result

### Derived from

QObject, black.Report

### Class Attributes

None

### Class Methods

None

### Methods

BlackReport | Constructor
done | Public method to handle the end of a reformat.
failed | Public method to handle a reformat failure.
path_ignored | Public method handling an ignored path.

### Static Methods

None

#### BlackReport (Constructor)

BlackReport(parent=None)

Constructor

parent (QObject (optional))
  reference to the parent object (defaults to None

#### BlackReport.done

done(src, changed, diff="")

Public method to handle the end of a reformat.

src (pathlib.Path)
  name of the processed file
changed (black.Changed)
  change status
diff (str)
  unified diff of potential changes (defaults to "")

#### BlackReport.failed

failed(src, message)

Public method to handle a reformat failure.

src (pathlib.Path)
  name of the processed file
message (str)
  error message

#### BlackReport.path_ignored

path_ignored(src, message="")

Public method handling an ignored path.

src (pathlib.Path or str)
  name of the processed file
message (str (optional))
  ignore message (default to "") (unused)

Up

## BlackStatistics

Class containing the reformatting statistic data.

### Derived from

None

### Class Attributes

changeCount
failureCount
ignoreCount
processedCount
sameCount

### Class Methods

None

### Methods

None

### Static Methods

None

Up